<html>
<head><meta charset="utf-8"><title>Assigning IDs to things · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html">Assigning IDs to things</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236195811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236195811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236195811">(Apr 26 2021 at 15:32)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> <span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> lets spit this off into a separate topic</p>



<a name="236196105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236196105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236196105">(Apr 26 2021 at 15:33)</a>:</h4>
<p>It seems that, overall, we arrived at this scheme for ids more or less universally:</p>
<p><code>type id = (id of enclosing thing, position in the parent)</code></p>



<a name="236198195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236198195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236198195">(Apr 26 2021 at 15:47)</a>:</h4>
<p>One annoying exception here is AstId and bdfs. I wonder if we can get rid of those? It seems like they perhaps belong to ItemTree level?</p>



<a name="236198289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236198289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236198289">(Apr 26 2021 at 15:48)</a>:</h4>
<p>That is, insterad of AstId (which is a position in syntax) we can use position in the item tree.</p>



<a name="236198547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236198547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236198547">(Apr 26 2021 at 15:50)</a>:</h4>
<p>Another annoying exception is <code>HirFileId</code>. It's root variant, <code>HirFileId::FileId</code> is sadly ambigious -- the same file might be included twice in the crate graph. I sort-of wish that <code>HirFileId</code> uniquely identified the source file (and a <code>(HirFileId, SyntaxNode)</code> pair uniquely identified a syntax node).</p>



<a name="236199538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236199538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236199538">(Apr 26 2021 at 15:56)</a>:</h4>
<p>I agree, did we ever try making <code>HirFileId::FileId</code> contain the crate?</p>



<a name="236199817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236199817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236199817">(Apr 26 2021 at 15:58)</a>:</h4>
<p>No</p>



<a name="236199869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236199869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236199869">(Apr 26 2021 at 15:58)</a>:</h4>
<p>Crate won't be enough -- I think it needs to be a Module</p>



<a name="236199910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236199910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236199910">(Apr 26 2021 at 15:59)</a>:</h4>
<p>hrm</p>



<a name="236200590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236200590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236200590">(Apr 26 2021 at 16:03)</a>:</h4>
<p>ah, because of <code>#[path]</code></p>



<a name="236200922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236200922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236200922">(Apr 26 2021 at 16:05)</a>:</h4>
<p>Hm, I guess that's complicated. There are really two uses for HirFileId</p>
<ul>
<li>an argument to <code>pares_or_expand</code> call</li>
<li>a way to identify stuff</li>
</ul>



<a name="236200999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236200999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236200999">(Apr 26 2021 at 16:05)</a>:</h4>
<p>I think the first one has to have the shape it has today. </p>
<p>The second one though feels like it should made unambigious</p>



<a name="236201475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Assigning%20IDs%20to%20things/near/236201475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Assigning.20IDs.20to.20things.html#236201475">(Apr 26 2021 at 16:09)</a>:</h4>
<p>yeah</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>